【C++STL】遍历算法(for | 您所在的位置:网站首页 › for each row活动解释 › 【C++STL】遍历算法(for |
【LeetCode】算法:两数之和(twoSum)解法分析
cft56200_ln: class Solution { public: vector twoSum(vector& nums, int target) { std::unordered_map myMap; vector result; for(int i = 0; i < nums.size(); i ++) { int complement = target - nums[i]; if (myMap.find(complement) != myMap.end()) { result.push_back(myMap[complement]); result.push_back(i); break; } myMap[nums[i]] = i; } return result; } }; |
CopyRight 2018-2019 实验室设备网 版权所有 |